﻿Public Class UIStatBars

    Public Type As BarType
    Public UserInterface As UserInterface
    Public Coordinates As Rectangle
    Public HPOverlay As Rectangle 'ToDo: Raise an event to change value rather than calling & processing a function every time.
    Public EnergyOverlay As Rectangle
    Public StaminaOverlay As Rectangle
    Public StatBackground As Rectangle
    Public Font As SpriteFont
    Public UIPlayerStats As Texture2D
    Public UITargetStats As Texture2D
    Public StatBar As Texture2D

    Public Enum BarType
        Player
        Target
        Group
    End Enum

    Public Property SetType As BarType
        Set(Type As BarType)
            Select Case Type
                Case BarType.Player
                    Me.Type = BarType.Player
                    Coordinates = New Rectangle(1, 1, 120, 20)
                Case BarType.Target
                    Me.Type = BarType.Target
                    Coordinates = New Rectangle(CInt(UserInterface.Width - 200), 1, 120, 20)
            End Select
            With Coordinates
                HPOverlay = New Rectangle(.X + 60, .Y + 30, .Width, .Height)
                EnergyOverlay = New Rectangle(.X + 60, .Y + 60, .Width, .Height)
                StaminaOverlay = New Rectangle(.X + 60, .Y + 90, .Width, .Height)
                StatBackground = New Rectangle(.X, .Y, UITargetStats.Width, UITargetStats.Height)
            End With
        End Set
        Get
            Return Me.Type
        End Get
    End Property

    Public Sub New(UserInterface As UserInterface)
        Me.UserInterface = UserInterface
        Font = UserInterface.TextureManager.GetTexture("Default").Font
        StatBar = UserInterface.TextureManager.GetTexture("Default").Texture2D
        UIPlayerStats = UserInterface.TextureManager.GetTexture("UIPlayerStats").Texture2D
        UITargetStats = UserInterface.TextureManager.GetTexture("UITargetStats").Texture2D
    End Sub

    Public Sub Draw(spriteBatch As SpriteBatch, ByVal Sprite As Sprite)
        Select Case Type
            Case BarType.Player
                spriteBatch.Draw(UIPlayerStats, StatBackground, Color.White)
                spriteBatch.DrawString(Font, Sprite.Stats.Name & " (HP: " & Sprite.Stats.HP & ")", New Vector2(15, 1), Color.Red)
            Case BarType.Target
                spriteBatch.Draw(UITargetStats, StatBackground, Color.White)
                spriteBatch.DrawString(Font, Sprite.Stats.Name & "(HP: " & Sprite.Stats.HP & ")", New Vector2(880, 1), Color.Red)
        End Select
        HPOverlay.Width = CInt((Sprite.Stats.HP / Sprite.Stats.HPMax) * 120)
        EnergyOverlay.Width = CInt((Sprite.Stats.Energy / Sprite.Stats.EnergyMax) * 120)
        StaminaOverlay.Width = CInt((Sprite.Stats.Stamina / Sprite.Stats.StaminaMax) * 120)
        spriteBatch.Draw(StatBar, HPOverlay, Color.Red)
        spriteBatch.Draw(StatBar, EnergyOverlay, Color.Blue)
        spriteBatch.Draw(StatBar, StaminaOverlay, Color.Yellow)
    End Sub

End Class
